//排行榜首页
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:tiktokadult/hj_page/find/rank_module/rank_type_tab_view.dart';
import 'package:tiktokadult/tools_base/indicator/custom_tab_indicator.dart';
import 'package:tiktokadult/tools_base/widget/keep_alive_widget.dart';
import 'rank_main_logic.dart';

class RankMainPage extends StatefulWidget {
  final int index;

  const RankMainPage({super.key, this.index = 0});

  @override
  State<RankMainPage> createState() => _RankMainPageState();
}

class _RankMainPageState extends State<RankMainPage> {
  late RankMainLogic logic = RankMainLogic(initIndex: widget.index);

  @override
  Widget build(BuildContext context) {
    return GetBuilder(
      init: logic,
      tag: "${DateTime.now().millisecondsSinceEpoch}",
      builder: (_) {
        return Scaffold(
          appBar: AppBar(title: Text('热门排行')),
          body: Column(
            children: [
              Container(
                height: 44,
                alignment: Alignment.center,
                child: TabBar(
                  padding: EdgeInsets.symmetric(horizontal: 30),
                  tabs: List.generate(
                    logic.tabs.length,
                    (index) => Padding(
                      padding: EdgeInsets.only(bottom: 5),
                      child: Text(logic.tabs[index].title),
                    ),
                  ),
                  labelPadding: EdgeInsets.symmetric(horizontal: 3),
                  unselectedLabelColor: Color(0x8CFFFFFF),
                  unselectedLabelStyle: TextStyle(fontSize: 16, fontWeight: FontWeight.w400),
                  labelColor: Color(0xE5FFFFFF),
                  labelStyle: TextStyle(fontSize: 14, fontWeight: FontWeight.w500),
                  controller: logic.tabCtr,
                  indicator: CustomIndicator(
                    height: 4,
                    width: 16,
                    useGradient: true,
                    gradientColors: [
                      Color(0xFFFD2D55),
                      Color(0xFFFD2D55),
                    ],
                    offsetY: 4,
                  ),
                ),
              ),
              Expanded(
                child: TabBarView(
                  controller: logic.tabCtr,
                  children: List.generate(
                    logic.tabCtr.length,
                    (index) {
                      return RankTypeTabView(logic.tabs[index]).keepAlive;
                    },
                  ),
                ),
              ),
            ],
          ),
        );
      },
    );
  }
}
